package com.hksj.cbm.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hksj.cbm.dto.DeviceModelDTO;
import com.hksj.cbm.entity.DeviceInstance;
import com.hksj.cbm.query.DeviceInstanceQuery;
import com.hksj.cbm.query.DeviceModelQuery;
import com.hksj.cbm.service.DeviceInstanceService;
import com.hksj.cbm.service.DeviceModelService;
import com.hksj.cbm.vo.DeviceModelVO;
import com.hksj.common.config.utils.PageResult;
import com.hksj.common.core.model.Rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @author zengke
 * @version 1.0
 * @see DeviceModelController
 * @since 2024/7/11 14:57
 */
@Api(tags = "基础模块-设备模型管理")
@RestController
@RequestMapping("/api/deviceModel")
public class DeviceModelController {

    @Autowired
    private DeviceModelService deviceModelService;

    @Autowired
    private DeviceInstanceService deviceInstanceService;

    @ApiOperation(value = "创建设备模型")
    @PostMapping("/createDeviceModel")
    public Rest<String> createDeviceModel(@RequestBody DeviceModelDTO deviceModelDTO){
        String result = deviceModelService.createDeviceModel(deviceModelDTO);
        return Rest.ok(result);
    }

    @ApiOperation(value = "更新设备模型")
    @PutMapping("/updateDeviceModel")
    public Rest<String> updateDeviceModel(@RequestBody DeviceModelDTO deviceModelDTO){
        String result = deviceModelService.updateDeviceModel(deviceModelDTO);
        return Rest.ok(result);
    }

    @ApiOperation(value = "删除设备模型")
    @DeleteMapping("/deleteDeviceModel")
    private Rest<String> deleteDeviceModel(Long id){
        String result = deviceModelService.deleteDeviceModel(id);
        return Rest.ok(result);
    }

    @ApiOperation(value = "分页查询设备模型列表")
    @PostMapping("/queryDeviceModelListByPaging")
    public Rest<PageResult<DeviceModelVO>> queryDeviceModelListByPaging(@RequestBody DeviceModelQuery deviceModelQuery){
        Page<DeviceModelVO> page = deviceModelService.queryDeviceModelListByPaging(deviceModelQuery);

        //封装分页结果
        PageResult<DeviceModelVO> result = PageResult.restPage(page);

        //返回结果
        return Rest.ok(result);
    }

    @ApiOperation(value = "分页查询设备实体列表")
    @PostMapping("/queryDeviceInstanceListByPaging")
    public Rest<PageResult<DeviceInstance>> queryDeviceInstanceListByPaging(@RequestBody DeviceInstanceQuery deviceInstanceQuery){
        Page<DeviceInstance> page = deviceInstanceService.queryDeviceInstanceListByPaging(deviceInstanceQuery);

        //封装分页结果
        PageResult<DeviceInstance> result = PageResult.restPage(page);

        //返回结果
        return Rest.ok(result);
    }

    @ApiOperation(value = "导出设备模型")
    @PostMapping("/exportDeviceModel")
    public void exportDeviceModel(@RequestBody DeviceModelQuery deviceModelQuery, HttpServletResponse response){
        deviceModelService.exportDeviceModel(deviceModelQuery,response);
    }

}
